package com.eorchis.module.baseuserinfo.ui.controller;

import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eorchis.core.service.IBaseService;
import com.eorchis.core.ui.commond.ResultState;
import com.eorchis.core.ui.controller.AbstractBaseController;
import com.eorchis.module.baseuserinfo.ui.commond.UserQueryCommond;
import com.eorchis.module.baseuserinfo.ui.commond.UserValidCommond;
import com.eorchis.module.classuser.ui.commond.ClassUserQueryCommond;
import com.eorchis.module.classuser.ui.controller.ClassUserController;
import com.eorchis.module.department.domain.DepartmentUser;
import com.eorchis.module.department.domain.DepartmentUserCondition;
import com.eorchis.module.department.service.IDepartmentUserService;
import com.eorchis.utils.utils.PropertyUtil;

@Controller("fsUserInfoController")
@RequestMapping(value = UserController.MODULE_PATH)
public class UserController extends AbstractBaseController<UserValidCommond, UserQueryCommond>
{
	public static final String MODULE_PATH = "/module/baseuserinfo";
	
	// 部门用户接口
	@Autowired
	@Qualifier("com.eorchis.module.department.service.impl.DepartmentUserServiceImpl")
	private IDepartmentUserService iDepartmentUserService;
//	@Override
	public IBaseService getService() 
	{
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * 查询用户详细信息
	 * @param queryCommond
	 * @return
	 * @throws Exception
	 * @author HuangTF
	 * @createDate 2012-12-10
	 */
	@RequestMapping(value = "/queryUserInfo")
	public String queryUserInfo(@ModelAttribute("result") UserValidCommond commond,
			HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute("resultState") ResultState resultState)throws Exception
	{
		DepartmentUserCondition condition=new DepartmentUserCondition();
		condition.setSearchUserId(commond.getUserId());
		DepartmentUser userInfo=iDepartmentUserService.getDepartmentUser(condition);

		if(PropertyUtil.objectNotEmpty(userInfo.getUser()))
		{
			commond.setEmail(userInfo.getUser().getEmail());
			commond.setMobileTelephone(userInfo.getUser().getMobileTelephone());
			commond.setPosition(userInfo.getUser().getDutyRemark());
			commond.setPhone(userInfo.getUser().getPhone());
			commond.setPaperNum(userInfo.getUser().getPaperNum());
			commond.setLoginID(userInfo.getUser().getLoginID());
			commond.setUserName(userInfo.getUser().getUserName());
			
//			if(PropertyUtil.objectNotEmpty(userInfo.getUser().getDutyLevelCode()))
//			{
//				commond.setDutyLevel(userInfo.getUser().getDutyLevelCode().getDataName());
//			}
//			if(PropertyUtil.objectNotEmpty(userInfo.getUser().getPoliticesCode()))
//			{
//				commond.setPolitices(userInfo.getUser().getPoliticesCode().getDataName());
//			}
//			if(PropertyUtil.objectNotEmpty(userInfo.getUser().getDegreeCode()))
//			{
//				commond.setDegree(userInfo.getUser().getDegreeCode().getDataName());
//			}
//			if(PropertyUtil.objectNotEmpty(userInfo.getUser().getSexCode()))
//			{
//				commond.setSex(userInfo.getUser().getSexCode().getDataName());
//			}
//			if(PropertyUtil.objectNotEmpty(userInfo.getUser().getFolkCode()))
//			{
//				commond.setFolk(userInfo.getUser().getFolkCode().getDataName());
//			}
//			if(PropertyUtil.objectNotEmpty(userInfo.getUser().getBirthday()))
//			{
//				commond.setBirthday(new SimpleDateFormat("yyyy-MM-dd").format(userInfo.getUser().getBirthday()));
//			}
		}
		
		if(PropertyUtil.objectNotEmpty(userInfo.getDepartment()))
		{
			commond.setDepName(userInfo.getDepartment().getDeptName());
		}
		resultState.setState(ResultState.RESULT_STATE_SUCCESS);
		resultState.setMessage("查询成功");
		return "";
	}
}
